Skip to content

grep: reject non-POSIX and unclosed [:name:] classes in BRE/ERE - #253

Open
yunusarda-sudo wants to merge 2 commits into
uutils:mainfrom
yunusarda-sudo:grep-validate-posix-char-classes
Open

yunusarda-sudo wants to merge 2 commits into
uutils:mainfrom
yunusarda-sudo:grep-validate-posix-char-classes

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

GNU grep accepts only the twelve POSIX class names inside a bracket expression (alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit). Any other name, such as [[:word:]], [[:ascii:]], the negated [[:^alpha:]] or the empty [[::]], fails with Invalid character class name and exit code 2. An unclosed [:, [., or [= inside a bracket expression (like [[:alpha]] or [x[:]y]) fails with Unmatched [, [^, [:, [., or [=.

Previously, scan_bracket only checked for misspelled [:space:] syntax without validating the class name or reporting unclosed subexpressions, allowing non-POSIX classes to pass through to Oniguruma.

This patch:

  • Validates POSIX class names inside [:...:] and errors with Invalid character class name on non-POSIX/negated names.
  • Reports Unmatched [, [^, [:, [., or [= when [:, [., or [= is not properly closed before the end of the bracket.
  • Preserves the existing [:space:] diagnostic.

Fixes #171

Investigated and verified locally with cargo fmt --all -- --check, cargo clippy -- -D warnings, and cargo test.

@codspeed

codspeed Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 3 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing yunusarda-sudo:grep-validate-posix-char-classes (4eb6988) with main (bf6f25e)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.23%. Comparing base (bf6f25e) to head (4eb6988).

Files with missing lines Patch % Lines
src/matcher.rs 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #253      +/-   ##
==========================================
+ Coverage   97.22%   97.23%   +0.01%     
==========================================
  Files           6        6              
  Lines        2270     2279       +9     
  Branches      245      246       +1     
==========================================
+ Hits         2207     2216       +9     
  Misses         63       63              
Flag Coverage Δ
macOS_latest 98.13% <96.15%> (+<0.01%) ⬆️
ubuntu_latest 98.13% <96.15%> (+<0.01%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown

GNU grep testsuite comparison:

Test results comparison:
  Current:   TOTAL: 128 / PASSED: 77 / FAILED: 30 / SKIPPED: 21
  Reference: TOTAL: 128 / PASSED: 76 / FAILED: 31 / SKIPPED: 21

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + ere

@github-actions

Copy link
Copy Markdown

GNU grep testsuite comparison:

Test results comparison:
  Current:   TOTAL: 128 / PASSED: 77 / FAILED: 30 / SKIPPED: 21
  Reference: TOTAL: 128 / PASSED: 76 / FAILED: 31 / SKIPPED: 21

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + ere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grep - accepts non-POSIX and malformed [:name:] classes that GNU rejects

1 participant